'use strict';
angular.module('clientApp')
.value('flightURL', 'http://127.0.0.1:8080/M2TIIL_AERO_2015')
.factory('flightAPI', function($http, flightURL) {
    return {
        add : function(flight) {
            return $http({
                url : flightURL + '/addFlight.htm?name=' + flight.name + '&departureTown=' + flight.departureTown + '&departureTime=' + flight.departureTime  + '&arrivalTown=' + flight.arrivalTown + '&arrivalTime=' + flight.arrivalTime,
                method : 'POST',
                headers : {
                    'Content-Type' : 'application/json'
                }
            });
        },
        remove : function(id){
        	return $http({
        		url : flightURL + '/removeFlight.htm?idFlight=' + id, 
        		method : 'GET',
        		headers : {
        			'Content-Type' : 'application/json'
        		}
        	});
        },
        modify : function(flight){
        	return $http({
        		url : flightURL + '/modifiyFlight.htm?idxFlight=' + flight.id + '&name=' + flight.name + '&departureTown=' + flight.departureTown + '&departureTime=' + flight.departureTime + '&arrivalTown=' + flight.arrivalTown + '&arrivalTime=' + flight.arrivalTime,
        		method : 'GET',
        		headers : {
        			'Content-Type' : 'application/json'
        		}
        	});
        },
        get : function(id){
        	return $http({
        		url : flightURL + '/getFlight.htm?idxFlight=' + id,
        		method : 'GET',
        		headers : {
        			'Content-Type' : 'application/json'
        		}
        	});
        },
        list : function(){
        	return $http({
        		url : flightURL + '/getFlights.htm',
        		method : 'GET',
        		headers : {
        			'Content-Type' : 'application/json'
        		}
        	});
        }
    };
});
